import React, { useEffect, useState } from 'react';
import { userApi } from '../../api';

const UserComponent: React.FC = () => {
  const [userInfo, setUserInfo] = useState<any>(null);
  
  useEffect(() => {
    const fetchUserInfo = async () => {
      try {
        const info = await userApi.getUserInfo();
        setUserInfo(info);
      } catch (error) {
        console.error('获取用户信息失败', error);
      }
    };
    
    fetchUserInfo();
  }, []);
  
  return (
    <div>
      {userInfo ? (
        <div>欢迎, {userInfo.username}</div>
      ) : (
        <div>加载中...</div>
      )}
    </div>
  );
};

export default UserComponent;